package cn.lingyangwl.agile.infra.gen.assembly;

import cn.lingyangwl.agile.infra.gen.model.*;
import cn.lingyangwl.agile.infra.gen.model.entity.*;
import cn.lingyangwl.agile.infra.gen.model.rqrs.*;
import cn.lingyangwl.agile.infra.gen.template.*;
import cn.lingyangwl.agile.infra.module.datamanage.db.*;
import cn.lingyangwl.framework.tool.core.*;
import org.mapstruct.*;

import java.util.List;

/**
 * @author shenguangyang
 */
@Mapper(componentModel = "spring", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface GenTableAssembly {
    GenTableColumn from(TableColumn tableColumn);
    GenTableDto toGenTableDto(GenTable genTable);

    void updateGenTableColumn(ColumnUnit columnUnit, @MappingTarget GenTableColumn genTableColumn);

    TmplJavaColumnDefinition toTmplJavaColumnDefinition(TmplColumnDefinition tmplColumnDefinition);

    TmplCsharpColumnDefinition toTmplCsharpColumnDefinition(TmplColumnDefinition tmplColumnDefinition);

    @Mappings({
            @Mapping(source = "columnComment", target = "comment"),
            @Mapping(source = "columnLength", target = "length"),
            @Mapping(source = "columnScale", target = "scale"),
            @Mapping(source = "columnType", target = "type"),
    })
    TmplColumnDefinition toTmplColumnDefinition(GenTableColumn genTableColumn);

    GenTableColumnResp toGenTableColumnRS(GenTableColumn genTableColumn);

    GenTableIndexResp toGenTableIndexRS(GenTableIndex genTableIndex);

    GenTableIndex toGenTableIndex(GenTableIndexReq genTableIndexReq);

    @Mappings({
            @Mapping(source = "columnNames", target = "columnNames", qualifiedByName = "toList")
    })
    TmplTableIndexDefinition toTmplTableIndexDefinition(GenTableIndex genTableIndex);

    @Named("toList")
    default List<String> toList(String str) {
        return StringUtils.toList(str, ",", String.class);
    }

    GenTableIndex toGenTableIndex(TableIndexDefinition item);

    GenInfoResp toGenInfoDto(GenTable source);

    GenTable toGenInfo(GeneratorReq source);
}
